package com.android.boncen.commonFrame.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.boncen.commonFrame.MyApplication;
import com.android.boncen.commonFrame.R;
import com.android.boncen.commonFrame.bean.CollectionBean;
import com.android.boncen.commonFrame.bean.ConsultationBean;
import com.android.boncen.commonFrame.bean.DoctorBean;
import com.android.boncen.commonFrame.tools.DesityUtil;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

/**
 * 功能描述:医生适配器
 *
 * @date 2017/2/8
 */

public class ConllectionDocAdapter extends BaseAdapter {

    private LayoutInflater inflater;

    public void setData(List<CollectionBean> data) {
        this.data.addAll(data);
        this.notifyDataSetChanged();
    }

    public List<CollectionBean> data = new ArrayList<>();

    public ConllectionDocAdapter(Context context)
    {
        super();
        inflater =LayoutInflater.from(context);

    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public CollectionBean getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHond hond=null;
        if (convertView ==null)
        {
            convertView = inflater.inflate(R.layout.doc_item,parent,false);
            hond = new ViewHond();
            hond.tvAttending = (TextView) convertView.findViewById(R.id.tvAttending);
            hond.tvName = (TextView) convertView.findViewById(R.id.tvName);
            hond.tvPosition = (TextView) convertView.findViewById(R.id.tvPosition);
            hond.tvHospital = (TextView) convertView.findViewById(R.id.tvHospital);
            hond.tvF = (TextView) convertView.findViewById(R.id.tvF);
            hond.ivHead =  (ImageView) convertView.findViewById(R.id.ivHead);
            convertView.setTag(hond);

        }else
        {
            hond = (ViewHond) convertView.getTag();
        }
        final DoctorBean bean = getItem(position).getDoc();
        hond.tvAttending.setText(bean.getAttending());
        hond.tvName.setText(bean.getName());
        hond.tvPosition.setText(bean.getDepartment() +" "+bean.getPosition());
        hond.tvHospital.setText(bean.getHospital());


        x.image().bind(hond.ivHead, bean.getImage(), MyApplication.getImageOptions());

        return convertView;
    }

    static  class ViewHond
    {
        ImageView ivHead;
        TextView tvF;
        TextView tvName;
        TextView tvPosition;
        TextView tvHospital;
        TextView  tvAttending;
    }

}
